package us.icitap.commandcenter.ui.shared;

import us.icitap.commandcenter.business.ejb.persistence.Call;
import us.icitap.commandcenter.ui.custom.CustColumnGenerator;
import us.icitap.commandcenter.ui.custom.CustTable;

import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

public class RelatedCallsVerticalLayout extends VerticalLayout{

	public RelatedCallsVerticalLayout(Call call) {
		
		if(call.getRelatedCallList() == null || call.getRelatedCallList().isEmpty()){
			Label l = new Label("<h2>Nuk ka telefonata te tjera te lidhur me kete telefonate</h2>", ContentMode.HTML);
			this.addComponent(l);
			
		}
		else{
			
			Label l = new Label("<h2>Telefonata te tjera te lidhura me kete telefonate</h2>", ContentMode.HTML);
			this.addComponent(l);
			
			BeanItemContainer<Call> beans = new BeanItemContainer<Call>(Call.class);

			CustTable t = new CustTable();
			t.setContainerDataSource(beans);
			t.setVisibleColumns(new Object[]{"caller", "address", "description", "callReason", "mainDispatcher", "forSupervisor", "recordDate"});
			t.setColumnHeaders(new String[]{ "TELEFONUESI", "ADRESA", "PERSHKRIMI", "ARSYEJA E TELEFONATES", "ZONA E MBULIMIT", "PER SUPERVIZORIN", "DT. REGJ."});
			t.addGeneratedColumn("caller", CustColumnGenerator.callerColumnGenerator);
			t.addGeneratedColumn("callReason", CustColumnGenerator.callReasonColumnGenerator);
			t.addGeneratedColumn("mainDispatcher", CustColumnGenerator.dispatcherColumnGenerator);
			t.addGeneratedColumn("forSupervisor", CustColumnGenerator.yesNoColumnGenerator);
			
			t.setPageLength(4);
			t.setWidth("950px");
			t.setColumnWidth("callReason", 100);
			t.setColumnWidth("forSupervisor", 30);
			t.setColumnWidth("address", 200);
			t.setColumnWidth("description", 200);
			
			beans.addAll(call.getRelatedCallList());
			this.setWidth("950px");
			this.addComponent(t);
		}
		
		
	}
}
